package hiber;

import hiber.hbm.Collection;
import hiber.hbm.User;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class TestPersistence {

	public static void main(String[] args) {

		// like discussed with regards to SessionFactory, an
		// EntityManagerFactory is set up once for an application
		// IMPORTANT: notice how the name here matches the name we gave the
		// persistence-unit in persistence.xml!
		EntityManagerFactory factory = Persistence
				.createEntityManagerFactory("hibernate.jpa");

		EntityManager manager = factory.createEntityManager();

		manager.getTransaction().begin();

		User user = new User();
		// user.setEmail("cororok@yahoo.com");
		// manager.persist(user);

		Collection collection = new Collection();
		collection.setFirstName("psd persistence");
		manager.persist(collection);

		manager.getTransaction().commit();

		manager.close();
		factory.close();

	}
}
